/**
 * ETFrameUI扩展共用组件
 */
layui.define('layer', function(exports) {
	
	var $ = layui.jquery;
	
	var mod = {
		// 时间工具
		getDateTime : function(format) {
			var date = new Date();
			var y = date.getFullYear();
			var m = date.getMonth() + 1;
			m = m < 10 ? ('0' + m) : m;
			var d = date.getDate();
			d = d < 10 ? ('0' + d) : d;
			var h = date.getHours();
			var minute = date.getMinutes();
			minute = minute < 10 ? ('0' + minute) : minute;
			var seconds = date.getSeconds();
			seconds = seconds < 10 ? ('0' + seconds) : seconds;
			// 存在
			if (format) {
				if (format == "yyyy-MM-dd") {
					return y + '-' + m + '-' + d
				}
				
				if (format == "yyyy-MM-dd HH:mm:ss") {
					return y + '-' + m + '-' + d + ' ' + h + ':' + minute + ':' + seconds;
				}
			}
			
			return y + '-' + m + '-' + d + ' ' + h + ':' + minute;
		},
		getDateForStr : function(date, format) {
			var y = date.getFullYear();
			var m = date.getMonth() + 1;
			m = m < 10 ? ('0' + m) : m;
			var d = date.getDate();
			d = d < 10 ? ('0' + d) : d;
			var h = date.getHours();
			var minute = date.getMinutes();
			minute = minute < 10 ? ('0' + minute) : minute;
			var seconds = date.getSeconds();
			seconds = seconds < 10 ? ('0' + seconds) : seconds;
			// 存在
			if (format) {
				if (format == "yyyy-MM-dd") {
					return y + '-' + m + '-' + d
				}
				
				if (format == "yyyy-MM-dd HH:mm:ss") {
					return y + '-' + m + '-' + d + ' ' + h + ':' + minute + ':' + seconds;
				}
			}
			return y + '-' + m + '-' + d + ' ' + h + ':' + minute;
		},
		formatDateTime : function(time) {
			
			// 适配所有浏览器
			time = time.replace(new RegExp(/-/gm), "/");
			if (time) {
				return new Date(time);
			}
			return new Date();
		},
		chkAllNum : function(str) {
			try {
				var r = str.match(/^\d+$/);
				return (r != null);
			} catch (e) {
				return false;
			}
		},
		// 检查字符串中是否含有特殊字符
		checkSpecialCharacter : function(str) {
			var pattern = new RegExp("[`~!@#$^&*()=|{}':;',\\[\\].<>/?~@#&*——|{}\"]");
			return pattern.test(str);
		},
		// 校验电话号码是否正确
		checkPhone : function(phone) {
			if ((/^[1][3,4,5,7,8][0-9]{9}$/.test(phone))) {
				return true;
			}
			return false;
		},
		// 去字符串两端空格
		trim : function(str) {
			var regBegSpace = /^(\s+)/;
			var regEndSpace = /(\s+)$/;
			var r = str.replace(regBegSpace, "").replace(regEndSpace, "");
			return r;
		},
		// 检查字符串是否是数字字母
		chkAllChar : function(str) {
			str = this.trim(str);
			try {
				var r = str.match(/^[A-Za-z]+$/);
				return (r != null);
			} catch (e) {
				return false;
			}
		},
		// 检查是否含有中文字符
		chkChinese : function(str) {
			try {
				var reg = /[^\x00-\xff]/;
				return reg.test(str);
			} catch (e) {
				return false;
			}
		}
	}
	// 输出
	exports('et_commutil', mod);
});